package com.hexiang.validator;

import com.hexiang.domain.vo.BookRequestVO;
import org.springframework.stereotype.Component;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import java.util.Arrays;
import java.util.List;

/**
 * 书籍名称是否存在校验器
 *
 * @author h01463
 * @version 1.0
 * @date 2024/7/25 16:51
 */
@Component
public class UniqueBookNameValidator implements ConstraintValidator<UniqueBookName, BookRequestVO> {

    List<String> bookList = Arrays.asList("test1", "test2");

    @Override
    public boolean isValid(BookRequestVO bookRequestVO, ConstraintValidatorContext context) {
        return !bookList.contains(bookRequestVO.getName());
    }
}
